<template>
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24" style="margin-top: 20px">
              <div class="table-page-search-wrapper">
                <a-form layout="inline" @keyup.enter.native="searchQuery">
                  <a-row :gutter="24">
                    <a-col :md="6" :sm="12">
                      <a-form-item label="名称">
                        <j-input placeholder="输入名称模糊查询" v-model="queryParam.name"></j-input>
                      </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="8">
                      <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                        <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                        <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px"
                          >重置</a-button
                        >
                      </span>
                    </a-col>
                  </a-row>
                </a-form>
              </div>
              <a-table
                ref="table"
                size="middle"
                :scroll="{ x: true }"
                bordered
                rowKey="id"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="ipagination"
                :loading="loading"
                :row-key="(record) => record.id"
                :row-selection="{
                  selectedRowKeys: selectedRowKeys,
                  onChange: onSelectChange,
                  onSelect: onSelect,
                  onSelectAll: onSelectAll
                }"
                class="j-table-force-nowrap"
                @change="handleTableChange"
                v-model="model.supplier"
              >
                <template slot="remark">
                    <span>
                      {{remark }}
                    </span>
                </template>
                <template slot="paymentMethod">
                    <span>
                      {{paymentMethod }}
                    </span>
                </template>
              </a-table>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
      
    </a-spin>
  
  </template>
  
  <script>
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  export default {
    name: 'WtPublicBiddingForm',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      JDate
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
     
     publicBiddingId:{
      type:String
     },
     supplierId:{
      type:String
     },
     remark:{
      type:String
     },
     paymentMethod:{
      type:String
     }
    },
    data() {
      return {
        dictOptions: {},
        superFieldList: [],
        remark:'',
        paymentMethod:'',
        queryParam: {type: '0', publicBiddingId: this.publicBiddingId,supplierId:this.supplierId},
        selectedRowKeys: [],
        selectedRows: [],
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          // {
          //   title: 'id',
          //   align: 'center',
          //   dataIndex: 'id'
          // },
          {
            title: '名称',
            align: 'center',
            dataIndex: 'platforMproductName'
          },
          {
            title: '数量',
            align: 'center',
            dataIndex: 'num'
          },
          {
            title: '单价',
            align: 'center',
            dataIndex: 'price'
          },
          {
            title: '税率',
            align: 'center',
            dataIndex: 'taxTate'
          },
          {
            title: '供货时间',
            align: 'center',
            dataIndex: 'deliveryTime'
          },
          {
            title: '总价',
            align: 'center',
            dataIndex: 'taxMoney'
          },
          {
            title: '付款说明',
            align: 'center',
            dataIndex: 'paymentMethod',
            scopedSlots: { customRender: 'paymentMethod' },
          },
          {
            title: '备注说明',
            align: 'center',
            dataIndex: 'remark',
            scopedSlots: { customRender: 'remark' },
          },
          // {
          //   title: '评分',
          //   align: 'center',
          //   dataIndex: 'score'
          // }
          
        ],
  
        model: {
          supplierId: ''
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        validatorRules: {},
        supplierData: [],
        // supplierList:[],
        url: {
          list: '/bidding/wtMaterialsSupplierPrice/list',
          add: '/bidding/wtMaterialsSupplierPrice/add',
          edit: '/bidding/wtMaterialsSupplierPrice/add',
          queryById: '/bidding/wtPublicBidding/queryById'
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      }
    },
  
    beforeMount(){
  
    },
    created() {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model))
    //  console.log('remark',this.remark);
    //  console.log('paymethod',this.paymentMethod);
   
    },
    methods: {
      initDictConfig() {},
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({ type: 'string', value: 'name', text: '名称', dictCode: '' })
        fieldList.push({ type: 'int', value: 'type', text: '0经营产品1施工', dictCode: '' })
        fieldList.push({ type: 'string', value: 'relation', text: '联系人', dictCode: '' })
        fieldList.push({ type: 'string', value: 'phone', text: '电话', dictCode: '' })
        fieldList.push({ type: 'string', value: 'address', text: '地址', dictCode: '' })
        fieldList.push({ type: 'string', value: 'score', text: '评分', dictCode: '' })
        this.superFieldList = fieldList
      },
      add() {
        this.edit(this.modelDefault)
      },
      edit(record) {
        this.model = Object.assign({}, record)
        this.visible = true
      },
      // 勾选触发的函数
      onSelectChange(selectedRowKeys) {
        this.selectedRowKeys = selectedRowKeys
      },
      /**
       * 表格单选事件
       * @param record 行数据
       * @param selected 是否选中
       */
      onSelect(record, selected) {
        // 若选中，直接push
        if (selected) {
          this.selectedRows.push(record)
        } else {
          // 若取消选中，则查找到这条数据删除
          let index = this.selectedRows.findIndex((item) => item.id == record.id)
          if (index >= 0) {
            this.selectedRows.splice(index, 1)
          }
        }
      },
      /**
       * 表格多选事件
       * @param selected     是否选中
       * @param selectedRows 忘记了，当时没用到
       * @param changeRows   变化行数据
       */
      onSelectAll(selected, selectedRows, changeRows) {
        // 若选中，直接push
        if (selected) {
          // 单选中部分几条数据，此时点击全选，将 changeRows 剩下的几条为选中数据选中
          this.selectedRows = this.selectedRows.concat(changeRows)
        } else {
          // 若取消选中，则为空
          this.selectedRows = []
        }
      },
      submitForm() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            let httpurl = ''
            let method = ''
            if (!this.model.supplierId) {
              httpurl += this.url.add
              method = 'post'
            } else {
              httpurl += this.url.edit
              method = 'post'
            }
            that.model.supplier = that.selectedRowKeys.join(',')
            httpAction(httpurl, that.model, method)
              .then(res => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.$emit('ok')
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.confirmLoading = false
              })
          }
        })
      }
    }
  }
  </script>
  